package com.singzi.leetcode.jianzhiOffer2;

import java.util.Scanner;

public class T0008 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int target = scanner.nextInt();
        int n = scanner.nextInt();
        int []nums = new int[n];
        for(int i = 0; i < n;i++){
            nums[i] = scanner.nextInt();
        }
        System.out.println(minSubArrayLen(target, nums));
    }

    private static int minSubArrayLen(int target, int[] nums) {
        if(nums.length == 1) return nums[0] >=target? 1:0;
        int min = Integer.MAX_VALUE;
        int left = 0, right = 0,sum = nums[0];
        while (right < nums.length){
            if(left == right && sum >= target) return 1;
            while (sum >= target){
                min = Math.min(min, right - left+1);
                sum -= nums[left];
                left++;
            }
            right++;
            if(right < nums.length) sum+=nums[right];

        }
        if(left == 0) return min < Integer.MAX_VALUE?min:0;
        return min;
    }
}
